home *** CD-ROM | disk | FTP | other *** search
/ Network CD 2 / Network CD - Volume 2.iso / twinopus / dopus / deletefile.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1995-07-08  |  8.2 KB  |  333 lines

  1. /*
  2.  *
  3.  * Delete file(s) and dirs with TwinExpress from DOpus.
  4.  *
  5.  * (c) 1994 by K.P. van Beem (2:280/464.2, patrick.van.beem@aobh.xs4all.nl)
  6.  *
  7.  * Based on the DOpusLhaARexx package by Geoff Seeley (but you can better
  8.  * use GuiArc in stead of DOpus and a script, to deal with archives)
  9.  *
  10.  *  Bug - The twin command "Delete" can be told to delete all files in all
  11.  *        subdirectories of a given subdir. BUT!! the command will not delete
  12.  *        all subdirectories of the given dir.
  13.  *        the command to do this is RMDIR (Remove Dir). BUT!! (there's that word
  14.  *        again) the command RMDIR can only remove a dir at a time.
  15.  *  Fix - Use the TREE command to build a list of all subdirectorys in the given
  16.  *        subdirectory and remove the one at a time. BUT!! if any spaces are in
  17.  *        the names of any of the SubDirectories, then the operation will fail
  18.  *        due to twin's problem with spaces in a file name !!
  19.  *         - this has not quite finished being written yet. will do it soon...
  20.  */
  21.  
  22. trace ?R
  23.  
  24. DOpusPort   = 'DOPUS.1'
  25.  
  26. if ~show(l,"rexxsupport.library") then
  27.     call addlib("rexxsupport.library",0,-30,0)
  28. if showlist('Ports', DOpusPort) = 0 then do
  29.    say 'Directory Opus Arexx port not found. Aborting.'
  30.    call CleanUp
  31. end
  32.  
  33. address 'DOPUS.1'
  34. options results
  35.  
  36. /* Get the current path and do file-deletion, depending on the  */
  37. /* type of path (Twin-path or normal path)                  */
  38. 'Status 6 -1'
  39. GetEntry Result
  40. FilePath = Result
  41.  
  42. if words(FilePath) > 1 then do
  43.    Request "Spaces in File/Dir Names are not Allowed !!"
  44.    exit
  45. end
  46.  
  47. TopText "Deleting selected files..."
  48.  
  49. if left(FilePath,1) ~= '*' then do
  50.    /* DOpus Way */
  51.    Delete
  52.    Busy off
  53.    exit
  54. end
  55. else do
  56.    request "Are you sure you want to DELETE all selected entries ?"
  57.    if result = 0 then do
  58.       exit
  59.    end
  60.  
  61.    busy on
  62.    FilePath = SubStr(FilePath,2)
  63.    GetSelectedAll
  64.    SelectedEntries = result
  65.    if SelectedEntries = 'RESULT' then do
  66.       TopText "No files selected."
  67.       call CleanUp
  68.    end
  69.  
  70.    SD = EnterDir(FilePath)
  71.  
  72.    NumberOfEntries = words(SelectedEntries)
  73.    do EntryNumber = 1 to NumberOfEntries
  74.       Index = word(SelectedEntries, EntryNumber)
  75.       SelectEntry Index 0 1
  76.       GetEntry Index+1
  77.       Entry = result
  78.       File = strip(left(Entry,25))
  79.  
  80.       filename = file
  81.       file = Quote(SD || file)
  82.  
  83.       if SubStr(Entry,26,9) = "Directory" then
  84.          extra = 'SUBDIR'
  85.       else
  86.          extra = ''
  87.  
  88.       /* delete all files in all subdirs */
  89.       address command 'echo >PPipe: delete' File extra
  90. /*
  91.       if SubStr(Entry,26,9) = "Directory" then do
  92.          address command 'echo >PPipe: y'
  93.          address command 'echo >PPipe: echo deleted'
  94.          address command 'echo >PPipe: help'
  95.          call WaitForAFile
  96.          call MakeATree
  97.          call TreeToPaths
  98.          call DeleteTree
  99.       end
  100. */
  101.    end
  102. end
  103.  
  104. TopText "Ready"
  105. 'DisplayDir -1'
  106. address AREXX "Rexx:DOpus/Reread.rexx"
  107. call CleanUp
  108.  
  109. exit
  110.  
  111. /*---------------------------------------------------------------------------*/
  112.  
  113. CleanUp: /* Remove any files and exit */
  114.    Busy off
  115.    exit
  116. return
  117.  
  118. /*--------------------------------------------------------------------------*/
  119.  
  120. Quote: procedure /* add quotes to string */
  121.    parse arg string
  122. return '"'||string||'"'
  123.  
  124. /*--------------------------------------------------------------------------*/
  125.  
  126. GetWord: procedure /* get word from '|' separated string */
  127.  
  128.   parse arg number,words
  129.  
  130.   if(left(words,1) ~= '|') then
  131.      words = '|'||words
  132.   do i=1 to number
  133.      idx = index(words, '|');
  134.      words = substr(words, idx+1)
  135.   end
  136.   end = index(words, '|') - 1
  137.   if words = "" then
  138.      return ""
  139.   ret_str = substr(words, 1, end)
  140. return ret_str
  141.  
  142. /*--------------------------------------------------------------------------*/
  143.  
  144. CountWords: procedure /* count words from '|' separated string */
  145.  
  146.    parse arg words
  147.  
  148.    count = 0
  149.    idx = index(words, '|')
  150.    do while idx ~= 0
  151.      count = count + 1
  152.      words = substr(words, idx+1)
  153.      idx = index(words, '|')
  154.    end
  155. return count
  156.  
  157. /*--------------------------------------------------------------------------*/
  158.  
  159. WaitForAFile:
  160.  
  161.    test = ''
  162.    /* received is for a normal copy,   sent is for a copy as */
  163.    if open(PipeList, "QUEUE:Twin", 'R') then do
  164.       do while (test ~= 'deleted')
  165.         junk = readln(PipeList)
  166.         test = right(junk , 7, '')
  167.       end
  168.       do while (test = 'deleted')
  169.         junk = readln(PipeList)
  170.         test = right(junk , 7, '')
  171.         if test = 'deleted' then
  172.            TopText junk
  173.       end
  174.       close(PipeList)
  175.    end
  176.  
  177.    /*check for errors and show user the error*/
  178.    fnd = find(junk,"Error:")
  179.    if fnd > 0 then do
  180.      Request right(junk,length(junk)-wordindex(junk,fnd)+1)
  181.      busy off
  182.      exit
  183.     end
  184. return
  185.  
  186. /*--------------------------------------------------------------------------*/
  187.  
  188. MakeATree:
  189.    TopText "Building a Tree of dir := " File
  190.  
  191.    open(DirTree, "T:DirTree", 'W')
  192.  
  193.    /* get a dir tree */
  194.    address command 'echo >PPipe: tree ' File
  195.    address command 'echo >PPipe: echo End-Of-Tree'
  196.    address command 'echo >PPipe: help'
  197.  
  198.    test = ''
  199.  
  200.    /* received is for a normal copy,   sent is for a copy as */
  201.    if open(PipeList, "QUEUE:Twin", 'R') then do
  202.       /* wait for the tree information to come in... */
  203.       do while ((test ~= 'Tree') & (test ~= 'End-Of-Tree'))
  204.         junk = readln(PipeList)
  205.         test = left(junk , 4, '')
  206.       end
  207.        /* now read in the Tree information */
  208.       do while (test ~= 'End-Of-Tree')
  209.         junk = readln(PipeList)
  210.         test = right(junk , 11, '')
  211.         writeln(DirTree, junk)
  212.       end
  213.       close(PipeList)
  214.    end
  215.  
  216.    close(DirTree)
  217. return
  218.  
  219. /*--------------------------------------------------------------------------*/
  220.  
  221. TreeToPaths:
  222.    TopText "Converting DirTree " File " to paths for deletion..."
  223. /*
  224. trace ?r
  225.    open(DirTree,  "T:DirTree",  'R')
  226.    open(TreePath, "T:TreePath", 'W')
  227.  
  228.    test = ''
  229.    lastname = ''
  230.    first = TRUE
  231.    skip  = FALSE
  232.    gap   = 6
  233.    do while (test ~= 'End-Of-Tree')
  234.      junk = readln(DirTree)
  235.      test = right(junk , 11, '')
  236.  
  237.      if length(junk) > 3 then do
  238.         name = right(junk,length(junk)-3)
  239.         Done = False
  240.         cnt = 1
  241.  
  242.         if first = False then
  243. /*         do*/
  244.             if left(name,gap-3) = space("",gap) then do
  245.                  lastname = deletelastname(lastname)
  246.                  if left(junk,3) = "   " then do
  247.                    lastname = lastname || '/' || substr(junk,gap+1,length(junk)-gap)
  248.                    skip = True
  249.                    gap  = gap + 3
  250.                    Done = True
  251.                  end
  252.                  gap = gap - 3
  253.             end
  254. /*            if Done = False then
  255.                gap = gap + 3 */
  256.             cnt = cnt + 1
  257. /*          while Done = False */
  258.  
  259.         if first = TRUE then do
  260.            lastname = name
  261.            first = FALSE
  262.            skip  = TRUE
  263.         end
  264.  
  265.         if (test ~= 'End-Of-Tree') then do
  266.            if skip = FALSE then
  267.               writeln(TreePath, Filename || '/' || lastname || name)
  268.            else
  269.               writeln(TreePath, Filename || '/' || lastname )
  270.  
  271.            skip = FALSE
  272.         end
  273.      end
  274.    end
  275.  
  276.    close(DirTree )
  277.    close(TreePath)
  278. */
  279. return
  280.  
  281. DeleteLastName: procedure
  282.    parse arg string
  283.    bit = ''
  284.    pos = length(string)
  285.    count = 0
  286.    do while((bit ~= ":") & (bit ~= "/") & (pos > 1))
  287.      bit = substr(string, pos, 1)
  288.      pos = pos - 1
  289.      count = count + 1
  290.    end
  291.  
  292.    if pos > 1 then
  293.       rtn = left(string, length(string)-count)
  294.    else
  295.       rtn = string
  296.  
  297. return rtn
  298.  
  299. /*--------------------------------------------------------------------------*/
  300.  
  301. DeleteTree:
  302.  
  303. return
  304.  
  305. /*--------------------------------------------------------------------------*/
  306.  
  307. /* Cd into the sent Directory path
  308.    - this is needed, as TWIN has a command parameter limi of 30 characters,
  309.       and as we all know AmigaDos file & paths can easily go over this limit !!*/
  310.  
  311. EnterDir: procedure
  312.  
  313.    parse arg Dev ':' Path
  314.  
  315.    /* get the 1st character to ddress the local or remote machine correctly */
  316.    if left(Dev,1) = '~' then
  317.       sbit = '~'
  318.      else
  319.       sbit = ''
  320.  
  321.    /* does the passed name have a DEVICE in it ? */
  322.    if Dev ~= '' then
  323.       address command 'echo >PPipe: cd' Dev || ':'
  324.  
  325.    do until (t2 = '')
  326.       parse var Path t1 '/' t2
  327.       path = t2
  328.       if t1 ~= '' then
  329.          address command 'echo >PPipe: cd' sbit || t1
  330.    end
  331.  
  332. return sbit
  333.